<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    

<head><meta name="generator" content="Hexo 3.8.0">
    <meta charset="utf-8">
    <meta name="keywords" content="移动自动化测试, Zhou•Yong">
    <meta name="description" content="移动自动化1.java环境2.Android SDK3.模拟器/真机4.常用操作
java安装jdk-8u151-windows-x64.exe
配置环境变量
    自定义变量JAVA_HOME=C:\Program Files\Java">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <title>移动自动化测试 | Zhou•Yong</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/css/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-2.2.0.min.js"></script>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>

</head>

<body>

<header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="container">
            <div class="nav-wrapper">
                <div class="brand-logo">
                    <a href="/" class="waves-effect waves-light">
                        
                        <img src="/medias/logo.png" class="logo-img hide-on-small-only">
                        
                        <span class="logo-span">Zhou•Yong</span>
                    </a>
                </div>
                <a href="#" data-activates="mobile-nav" class="button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right">
    
    <li class="hide-on-med-and-down">
        <a href="/" class="waves-effect waves-light">
            
            <i class="fa fa-home"></i>
            
            <span>主页</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/about" class="waves-effect waves-light">
            
            <i class="fa fa-user-circle-o"></i>
            
            <span>个人介绍</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/categories" class="waves-effect waves-light">
            
            <i class="fa fa-bookmark"></i>
            
            <span>分类</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/tags" class="waves-effect waves-light">
            
            <i class="fa fa-tags"></i>
            
            <span>标签</span>
        </a>
    </li>
    
    <li class="hide-on-med-and-down">
        <a href="/friends" class="waves-effect waves-light">
            
            <i class="fa fa-address-book"></i>
            
            <span>推荐</span>
        </a>
    </li>
    
    <li>
        <a id="toggleSearch" class="waves-effect waves-light">
            <i id="searchIcon" class="mdi-action-search"></i>
        </a>
    </li>

</ul>

<div class="side-nav" id="mobile-nav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">Zhou•Yong</div>
        <div class="logo-desc">
            
            你迈出的步伐不非得很大，只要你是在正确的方向前进就行
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li>
            <a href="/" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-home"></i>
                
                主页
            </a>
        </li>
        
        <li>
            <a href="/about" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-user-circle-o"></i>
                
                个人介绍
            </a>
        </li>
        
        <li>
            <a href="/categories" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-bookmark"></i>
                
                分类
            </a>
        </li>
        
        <li>
            <a href="/tags" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-tags"></i>
                
                标签
            </a>
        </li>
        
        <li>
            <a href="/friends" class="waves-effect waves-light">
                
                <i class="fa fa-fw fa-address-book"></i>
                
                推荐
            </a>
        </li>
        
        
    </ul>

    <div class="social-link"><a href="#!" class="tooltipped" data-tooltip="邮件联系我: zy20081@126.com" data-position="top" data-delay="50">
    <i class="fa fa-envelope-open"></i>
</a>
<a href="#!" class="tooltipped" data-tooltip="QQ联系我: 314153271" data-position="top" data-delay="50">
    <i class="fa fa-qq"></i>
</a>

<a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
    <i class="fa fa-rss"></i>
</a>
</div>
</div>

            </div>
        </div>

        
    </nav>
</header>





<div class="bg-cover post-cover" style="background-image: url('/medias/featureimages/21.jpg')">
    <div class="container">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <div class="description center-align post-title">
                        移动自动化测试
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>



<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1,
    #articleContent h2,
    #articleContent h3,
    #articleContent h4,
    #articleContent h5,
    #articleContent h6 {
        padding-top: 76px;
        margin-top: -76px;
    }

    #articleContent h1 {
        line-height: 3.5rem;
    }

    #articleContent h2 {
        line-height: 3.2rem;
    }

    #articleContent h3 {
        line-height: 2.8rem;
    }

    #articleContent h4 {
        line-height: 2.5rem;
    }

    #articleContent h5 {
        line-height: 2.2rem;
    }

    #articleContent h6 {
        line-height: 1.9rem;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        margin: 35px 0 15px 0;
        padding-left: 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #toc-content .is-active-link::before {
        background-color: #42b983;
    }
</style>
<div class="row">
    <div class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            
            <div class="article-tag">
                
                <a href="/tags/移动自动化测试/" target="_blank">
                    <span class="chip bg-color">移动自动化测试</span>
                </a>
                
            </div>
            
            <div class="post-info">
                
                <span class="post-cate">
                    <i class="fa fa-bookmark fa-fw icon-category"></i>
                    
                    <a href="/categories/测试/" class="post-category" target="_blank">
                        测试
                    </a>
                    
                </span>
                

                <span class="post-date">
                    <i class="fa fa-clock-o fa-fw"></i>2020-11-08
                </span>
            </div>
        </div>
        <hr>
        <div class="card-content article-card-content">
            <div id="articleContent">
                <h2 id="移动自动化"><a href="#移动自动化" class="headerlink" title="移动自动化"></a>移动自动化</h2><p>1.java环境<br>2.Android SDK<br>3.模拟器/真机<br>4.常用操作</p>
<h2 id="java"><a href="#java" class="headerlink" title="java"></a>java</h2><pre class=" language-bash"><code class="language-bash">安装jdk-8u151-windows-x64.exe
配置环境变量
    自定义变量JAVA_HOME<span class="token operator">=</span>C:\Program Files\Java\jdk1.8.0_151
    注意：C:\Program Files\Java\jdk1.8.0_151 为jdk的安装目录
配置path
    %JAVA_HOME%\bin
    %JAVA_HOME%\jre\bin
验证
    终端输入：java -version
    终端输入：javac -version
3.Android SDK 安装
    解压android-sdk.zip到指定目录
配置环境变量
    自定义变量 ANDROID_HOME<span class="token operator">=</span>C:\tools\android-sdk
    C:\tools\android-sdk是你的解压目录
    platform-tools文件夹和tools文件夹都在C:\tools\android-sdk下
配置path
    C:\Users\liuzhaowen<span class="token operator">></span>java -version
    java version <span class="token string">"1.8.0_151"</span>
    Java<span class="token punctuation">(</span>TM<span class="token punctuation">)</span> SE Runtime Environment <span class="token punctuation">(</span>build 1.8.0_151-b12<span class="token punctuation">)</span>
    Java HotSpot<span class="token punctuation">(</span>TM<span class="token punctuation">)</span> 64-Bit Server VM <span class="token punctuation">(</span>build 25.151-b12, mixed mode<span class="token punctuation">)</span>
    C:\Users\liuzhaowen<span class="token operator">></span>javac -version
    javac 1.8.0_151
</code></pre>
<h2 id="安装模拟器"><a href="#安装模拟器" class="headerlink" title="安装模拟器"></a>安装模拟器</h2><pre class=" language-bash"><code class="language-bash">模拟器Genymotion安装
</code></pre>
<h2 id="安装UIAutomatorViewer"><a href="#安装UIAutomatorViewer" class="headerlink" title="安装UIAutomatorViewer"></a>安装UIAutomatorViewer</h2><pre class=" language-bash"><code class="language-bash">查看《设置》应用程序右上角 ”放大镜“ 按钮的 ”resource-id“
1. 打开 uiautomatorviewer
2. 打开 android 模拟器
3. 启动《设置》应用程序
4. 点击 Device Screenshot 按钮
5. 点击 ”放大镜“ 按钮
6. 查看 Node Detail 中的 ”resource-id“ 信息
</code></pre>
<p><img src="/2020/11/08/yi-dong-zi-dong-hua/1.jpg" alt="图1"><br><img src="/2020/11/08/yi-dong-zi-dong-hua/2.jpg" alt="图2"></p>
<h2 id="Appium自动化测试"><a href="#Appium自动化测试" class="headerlink" title="Appium自动化测试"></a>Appium自动化测试</h2><pre class=" language-bash"><code class="language-bash">1.appium-desktop-Setup-1.6.2.exe，默认安装即可
2.Appium-python库安装:pip3 <span class="token function">install</span> Appium-Python-Client
测试成功：
from appium <span class="token function">import</span> webdriver
<span class="token function">import</span> <span class="token function">time</span>

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 平台的名字，大小写无所谓，不能乱写</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'andRoId'</span>
<span class="token comment" spellcheck="true"># 平台的版本，（5.4.3 可以写 5.4.3，5.4，5）</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5'</span>
<span class="token comment" spellcheck="true"># 设备的名字，随便写，不能乱写</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'1'</span>
<span class="token comment" spellcheck="true"># 要打开的应用程序</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.cyanogenmod.filemanager'</span>
<span class="token comment" spellcheck="true"># 要打开的界面</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.activities.NavigationActivity'</span>

driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>

time.sleep<span class="token punctuation">(</span>5<span class="token punctuation">)</span>

driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>


</code></pre>
<h2 id="测试环境"><a href="#测试环境" class="headerlink" title="测试环境"></a>测试环境</h2><pre class=" language-bash"><code class="language-bash">1. 导包
from selenium <span class="token function">import</span> webdriver
2. 创建浏览器驱动对象
Firefox浏览器：driver <span class="token operator">=</span> webdriver.Firefox<span class="token punctuation">(</span><span class="token punctuation">)</span>
Chrome浏览器：driver <span class="token operator">=</span> webdriver.Chrome<span class="token punctuation">(</span><span class="token punctuation">)</span>
Edge浏览器：driver <span class="token operator">=</span> webdriver.Edge<span class="token punctuation">(</span><span class="token punctuation">)</span>
3. 打开Web页面
driver.get<span class="token punctuation">(</span><span class="token string">"http://www.baidu.com/"</span><span class="token punctuation">)</span>
4. 暂停
time.sleep<span class="token punctuation">(</span>3<span class="token punctuation">)</span>
5. 关闭驱动对象
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
<h2 id="常用API"><a href="#常用API" class="headerlink" title="常用API"></a>常用API</h2><h3 id="基本API"><a href="#基本API" class="headerlink" title="基本API"></a>基本API</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 手机参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
<span class="token comment" spellcheck="true"># 应用参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.Settings'</span>

<span class="token comment" spellcheck="true"># 获取driver</span>
driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>

print<span class="token punctuation">(</span><span class="token string">"---- 准备进入后台 ----"</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># 进入后台5秒，再回到前台</span>
driver.background_app<span class="token punctuation">(</span>5<span class="token punctuation">)</span>

print<span class="token punctuation">(</span><span class="token string">"---- 已经回到前台 ----"</span><span class="token punctuation">)</span>

time.sleep<span class="token punctuation">(</span>5<span class="token punctuation">)</span>
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># # 判断安智市场是否已经安装</span>
<span class="token comment" spellcheck="true"># if driver.is_app_installed("cn.goapk.market"):</span>
<span class="token comment" spellcheck="true">#     # 如果安装，就要卸载</span>
<span class="token comment" spellcheck="true">#     driver.remove_app("cn.goapk.market")</span>
<span class="token comment" spellcheck="true"># else:</span>
<span class="token comment" spellcheck="true">#     # 如果没有安装，就要安装</span>
<span class="token comment" spellcheck="true">#     driver.install_app("/Users/Yoson/Desktop/anzhishichang.apk")</span>




<span class="token comment" spellcheck="true"># driver.close_app()</span>
<span class="token comment" spellcheck="true"># driver.quit()</span>

<span class="token comment" spellcheck="true"># print(driver.current_package)</span>

<span class="token comment" spellcheck="true"># # 等待三秒</span>
<span class="token comment" spellcheck="true"># time.sleep(3)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 输出当前程序的包名</span>
<span class="token comment" spellcheck="true"># print(driver.current_package)</span>
<span class="token comment" spellcheck="true"># # 输出当前程序的界面名</span>
<span class="token comment" spellcheck="true"># print(driver.current_activity)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 启动短信应用程序</span>
<span class="token comment" spellcheck="true"># driver.start_activity("com.android.mms", ".ui.ConversationList")</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 输出当前程序的包名</span>
<span class="token comment" spellcheck="true"># print(driver.current_package)</span>
<span class="token comment" spellcheck="true"># # 输出当前程序的界面名</span>
<span class="token comment" spellcheck="true"># print(driver.current_activity)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># time.sleep(20)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 退出driver</span>
<span class="token comment" spellcheck="true"># driver.quit()</span>
</code></pre>
<h3 id="元素定位"><a href="#元素定位" class="headerlink" title="元素定位"></a>元素定位</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.Settings'</span>

driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># -------------------- 定位一个元素</span>
<span class="token comment" spellcheck="true"># # 通过 id 定位放大镜按钮，点击</span>
<span class="token comment" spellcheck="true"># # search_button = driver.find_element_by_id("com.android.settings:id/search")</span>
<span class="token comment" spellcheck="true"># driver.find_element_by_id("com.android.settings:id/search").click()</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 通过 class 定位输入框，输入hello</span>
<span class="token comment" spellcheck="true"># driver.find_element_by_class_name("android.widget.EditText").send_keys("hello")</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 通过 xpath 定位返回按钮，点击</span>
<span class="token comment" spellcheck="true"># driver.find_element_by_xpath("//*[@content-desc='收起']").click()</span>

<span class="token comment" spellcheck="true"># -------------------- 定位一组元素</span>
<span class="token comment" spellcheck="true"># 通过 id 形式，获取所有id为 ”com.android.settings:id/title“ 的元素，并且打印文字内容</span>
<span class="token comment" spellcheck="true"># titles = driver.find_elements_by_id("com.android.settings:id/title")</span>
<span class="token comment" spellcheck="true"># # print(titles)</span>
<span class="token comment" spellcheck="true"># # print(len(titles))</span>
<span class="token comment" spellcheck="true"># # for title in titles:</span>
<span class="token comment" spellcheck="true"># #     print(title.text)</span>
<span class="token comment" spellcheck="true"># titles[1].click()</span>

<span class="token comment" spellcheck="true"># 通过 class_name 的形式，获取所有class 为 ”android.widget.TextView“ 的元素，并打印其文字内容</span>
<span class="token comment" spellcheck="true"># textviews = driver.find_elements_by_class_name("android.widget.TextView")</span>
<span class="token comment" spellcheck="true"># print(len(textviews))</span>
<span class="token comment" spellcheck="true"># for textview in textviews:</span>
<span class="token comment" spellcheck="true">#     print(textview.text)</span>

<span class="token comment" spellcheck="true"># 通过 xpath 的形式，获取所有包含 ”设“ 的元素，并打印其文字内容</span>
<span class="token comment" spellcheck="true"># eles = driver.find_elements_by_xpath("//*[contains(@text,'设')]")</span>
<span class="token comment" spellcheck="true"># print(len(eles))</span>
<span class="token comment" spellcheck="true"># for i in eles:</span>
<span class="token comment" spellcheck="true">#     print(i.text)</span>

<span class="token comment" spellcheck="true"># ------------ 注意点</span>
<span class="token comment" spellcheck="true"># button = driver.find_element_by_id("xxxxxxx")</span>
<span class="token comment" spellcheck="true"># button.click()</span>

eles <span class="token operator">=</span> driver.find_elements_by_id<span class="token punctuation">(</span><span class="token string">"xxxx"</span><span class="token punctuation">)</span>
print<span class="token punctuation">(</span>eles<span class="token punctuation">)</span>
<span class="token keyword">for</span> i <span class="token keyword">in</span> eles:
    print<span class="token punctuation">(</span>i<span class="token punctuation">)</span>


time.sleep<span class="token punctuation">(</span>5<span class="token punctuation">)</span>

driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
<h3 id="元素等待"><a href="#元素等待" class="headerlink" title="元素等待"></a>元素等待</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver
from selenium.webdriver.support.wait <span class="token function">import</span> WebDriverWait

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.Settings'</span>

driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>


<span class="token comment" spellcheck="true"># ------- 隐式等待</span>
<span class="token comment" spellcheck="true"># driver.implicitly_wait(10)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># print("---准备找返回进行点击")</span>
<span class="token comment" spellcheck="true"># driver.find_element_by_xpath("//*[@content-desc='收起']").click()</span>
<span class="token comment" spellcheck="true"># print("---点完了")</span>


<span class="token comment" spellcheck="true"># ------- 显式等待</span>

print<span class="token punctuation">(</span><span class="token string">"---准备找返回进行点击"</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># wait = WebDriverWait(driver, 25, 5)</span>
<span class="token comment" spellcheck="true"># back_button = wait.until(lambda x: x.find_element_by_xpath("//*[@content-desc='收起']"))</span>
<span class="token comment" spellcheck="true"># back_button.click()</span>

<span class="token comment" spellcheck="true"># back_button = WebDriverWait(driver, 5, 1).until(lambda x: x.find_element_by_xpath("//*[@content-desc='收起']"))</span>
<span class="token comment" spellcheck="true"># back_button.click()</span>

<span class="token comment" spellcheck="true"># WebDriverWait(driver, 5, 1).until(lambda x: x.find_element_by_xpath("//*[@content-desc='收起']")).click()</span>

<span class="token comment" spellcheck="true"># 使用显示等待，在20秒的时间内，每3秒钟找一次，id为xxx的元素</span>
WebDriverWait<span class="token punctuation">(</span>driver, 20, 3<span class="token punctuation">)</span>.until<span class="token punctuation">(</span>lambda x: x.find_element_by_id<span class="token punctuation">(</span><span class="token string">"xxx"</span><span class="token punctuation">))</span>


print<span class="token punctuation">(</span><span class="token string">"---点完了"</span><span class="token punctuation">)</span>



time.sleep<span class="token punctuation">(</span>5<span class="token punctuation">)</span>
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
<h3 id="元素操作"><a href="#元素操作" class="headerlink" title="元素操作"></a>元素操作</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.Settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'unicodeKeyboard'</span><span class="token punctuation">]</span> <span class="token operator">=</span> True
desired_caps<span class="token punctuation">[</span><span class="token string">'resetKeyboard'</span><span class="token punctuation">]</span> <span class="token operator">=</span> True

driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>

time.sleep<span class="token punctuation">(</span>2<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># 点击</span>
<span class="token comment" spellcheck="true"># driver.find_element_by_id("com.android.settings:id/search").click()</span>

<span class="token comment" spellcheck="true"># 输入和清空输入框</span>
<span class="token comment" spellcheck="true"># # 2. 点击 ”放大镜“</span>
<span class="token comment" spellcheck="true"># driver.find_element_by_id("com.android.settings:id/search").click()</span>
<span class="token comment" spellcheck="true"># # 3. 输入 ”hello“</span>
<span class="token comment" spellcheck="true"># input_label = driver.find_element_by_id("android:id/search_src_text")</span>
<span class="token comment" spellcheck="true"># input_label.send_keys("hello")</span>
<span class="token comment" spellcheck="true"># # 4. 暂停 2 秒</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># # 5. 清空所有文本内容</span>
<span class="token comment" spellcheck="true"># input_label.clear()</span>
<span class="token comment" spellcheck="true"># # 6. 暂停 5 秒</span>
<span class="token comment" spellcheck="true"># time.sleep(5)</span>
<span class="token comment" spellcheck="true"># # 7. 输入 ”你好“</span>
<span class="token comment" spellcheck="true"># print("----")</span>
<span class="token comment" spellcheck="true"># input_label.send_keys("你好")</span>
<span class="token comment" spellcheck="true"># print("----")</span>

<span class="token comment" spellcheck="true"># 获取文本内容</span>
<span class="token comment" spellcheck="true"># eles = driver.find_elements_by_id("com.android.settings:id/title")</span>
<span class="token comment" spellcheck="true"># for i in eles:</span>
<span class="token comment" spellcheck="true">#     print(i.text)</span>

<span class="token comment" spellcheck="true"># 获取元素的位置和大小</span>
<span class="token comment" spellcheck="true"># search_button = driver.find_element_by_id("com.android.settings:id/search")</span>
<span class="token comment" spellcheck="true"># print(search_button.location)</span>
<span class="token comment" spellcheck="true"># print(search_button.location["x"])</span>
<span class="token comment" spellcheck="true"># print(search_button.location["y"])</span>
<span class="token comment" spellcheck="true"># print(search_button.size)</span>
<span class="token comment" spellcheck="true"># print(search_button.size["width"])</span>
<span class="token comment" spellcheck="true"># print(search_button.size["height"])</span>

<span class="token comment" spellcheck="true"># 获取元素的属性值</span>
<span class="token comment" spellcheck="true"># eles = driver.find_elements_by_id("com.android.settings:id/title")</span>
<span class="token comment" spellcheck="true"># for i in eles:</span>
<span class="token comment" spellcheck="true">#     print(i.get_attribute("enabled"))</span>
<span class="token comment" spellcheck="true">#     print(i.get_attribute("clickable"))</span>
<span class="token comment" spellcheck="true">#     print(i.get_attribute("text"))</span>
<span class="token comment" spellcheck="true">#     print(i.get_attribute("resourceId"))</span>
<span class="token comment" spellcheck="true">#     print(i.get_attribute("className"))</span>

eles <span class="token operator">=</span> driver.find_elements_by_class_name<span class="token punctuation">(</span><span class="token string">"android.widget.TextView"</span><span class="token punctuation">)</span>
<span class="token keyword">for</span> i <span class="token keyword">in</span> eles:
    print<span class="token punctuation">(</span>i.get_attribute<span class="token punctuation">(</span><span class="token string">"text"</span><span class="token punctuation">))</span>
    print<span class="token punctuation">(</span>i.get_attribute<span class="token punctuation">(</span><span class="token string">"name"</span><span class="token punctuation">))</span>

time.sleep<span class="token punctuation">(</span>5<span class="token punctuation">)</span>
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
<h3 id="滑动和拖拽事件"><a href="#滑动和拖拽事件" class="headerlink" title="滑动和拖拽事件"></a>滑动和拖拽事件</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 手机参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
<span class="token comment" spellcheck="true"># 应用参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.Settings'</span>

<span class="token comment" spellcheck="true"># 获取driver</span>
driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>


<span class="token comment" spellcheck="true"># swipe ----------------------------</span>
<span class="token comment" spellcheck="true"># driver.swipe(100, 2000, 100, 1000)</span>
<span class="token comment" spellcheck="true"># driver.swipe(100, 2000, 100, 100)</span>
<span class="token comment" spellcheck="true"># driver.swipe(100, 2000, 100, 100, 5000)</span>

<span class="token comment" spellcheck="true"># 滑动的距离越长，展示的效果越靠后</span>
<span class="token comment" spellcheck="true"># 距离相同时，持续时间越长，惯性越小</span>

<span class="token comment" spellcheck="true"># scroll &amp; drag_and_drop ----------------------------</span>
save_button <span class="token operator">=</span> driver.find_element_by_xpath<span class="token punctuation">(</span><span class="token string">"//*[@text='存储']"</span><span class="token punctuation">)</span>
more_button <span class="token operator">=</span> driver.find_element_by_xpath<span class="token punctuation">(</span><span class="token string">"//*[@text='更多']"</span><span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># driver.scroll(save_button, more_button)</span>
driver.drag_and_drop<span class="token punctuation">(</span>save_button, more_button<span class="token punctuation">)</span>


time.sleep<span class="token punctuation">(</span>20<span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 退出driver</span>
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
<h3 id="手势TouchAction"><a href="#手势TouchAction" class="headerlink" title="手势TouchAction"></a>手势TouchAction</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver
from appium.webdriver.common.touch_action <span class="token function">import</span> TouchAction

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 手机参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
<span class="token comment" spellcheck="true"># 应用参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.Settings'</span>

<span class="token comment" spellcheck="true"># 获取driver</span>
driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># ------ 长按操作</span>
TouchAction<span class="token punctuation">(</span>driver<span class="token punctuation">)</span>.tap<span class="token punctuation">(</span>x<span class="token operator">=</span>650, y<span class="token operator">=</span>650<span class="token punctuation">)</span>.perform<span class="token punctuation">(</span><span class="token punctuation">)</span>
time.sleep<span class="token punctuation">(</span>2<span class="token punctuation">)</span>
TouchAction<span class="token punctuation">(</span>driver<span class="token punctuation">)</span>.long_press<span class="token punctuation">(</span>x<span class="token operator">=</span>650, y<span class="token operator">=</span>650, duration<span class="token operator">=</span>2000<span class="token punctuation">)</span>.perform<span class="token punctuation">(</span><span class="token punctuation">)</span>


<span class="token comment" spellcheck="true"># ------ 等待操作</span>
<span class="token comment" spellcheck="true"># TouchAction(driver).tap(x=650, y=650).perform()</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># TouchAction(driver).press(x=650, y=650).wait(2000).release().perform()</span>


<span class="token comment" spellcheck="true"># ------ 按下和抬起</span>
<span class="token comment" spellcheck="true"># TouchAction(driver).press(x=650, y=650).perform()</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># TouchAction(driver).press(x=650, y=650).perform()</span>

<span class="token comment" spellcheck="true"># TouchAction(driver).press(x=650, y=650).perform()</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># TouchAction(driver).press(x=650, y=650).release().perform()</span>


<span class="token comment" spellcheck="true"># ------ 轻敲</span>
<span class="token comment" spellcheck="true"># 找到要点击的元素</span>
<span class="token comment" spellcheck="true"># wlan_button = driver.find_element_by_xpath("//*[@text='WLAN']")</span>
<span class="token comment" spellcheck="true"># 1. 创建touchaction对象</span>
<span class="token comment" spellcheck="true"># 2. 调用想要执行的动作</span>
<span class="token comment" spellcheck="true"># 3. 使用perform执行动作</span>
<span class="token comment" spellcheck="true"># TouchAction(driver).tap(wlan_button).perform()</span>
<span class="token comment" spellcheck="true"># TouchAction(driver).tap(x=650, y=650).perform()</span>

<span class="token comment" spellcheck="true"># # 1. 创建touchaction对象</span>
<span class="token comment" spellcheck="true"># touch_action = TouchAction(driver)</span>
<span class="token comment" spellcheck="true"># # 2. 调用想要执行的动作</span>
<span class="token comment" spellcheck="true"># touch_action = touch_action.tap(wlan_button)</span>
<span class="token comment" spellcheck="true"># # 3. 使用perform执行动作</span>
<span class="token comment" spellcheck="true"># touch_action.perform()</span>


time.sleep<span class="token punctuation">(</span>10<span class="token punctuation">)</span>
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>

</code></pre>
<h3 id="draw"><a href="#draw" class="headerlink" title="draw"></a>draw</h3><pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true"># 导包</span>
<span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver
from appium.webdriver.common.touch_action <span class="token function">import</span> TouchAction

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 手机参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
<span class="token comment" spellcheck="true"># 应用参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.ChooseLockPattern'</span>

<span class="token comment" spellcheck="true"># 获取driver</span>
driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># 如果代码过长，可以使用回车进行换行</span>
<span class="token comment" spellcheck="true"># 换行的时候默认会多一个 右斜线 是正常的</span>
<span class="token comment" spellcheck="true"># 如果不希望出现这个 右斜线 可以将整句代码用括号括起来，然后再使用回车换行即可</span>

<span class="token punctuation">(</span>TouchAction<span class="token punctuation">(</span>driver<span class="token punctuation">)</span>.press<span class="token punctuation">(</span>x<span class="token operator">=</span>244, y<span class="token operator">=</span>856<span class="token punctuation">)</span>.move_to<span class="token punctuation">(</span>x<span class="token operator">=</span>721, y<span class="token operator">=</span>843<span class="token punctuation">)</span>
 .move_to<span class="token punctuation">(</span>x<span class="token operator">=</span>1203, y<span class="token operator">=</span>846<span class="token punctuation">)</span>.move_to<span class="token punctuation">(</span>x<span class="token operator">=</span>1197, y<span class="token operator">=</span>1346<span class="token punctuation">)</span>
 .move_to<span class="token punctuation">(</span>x<span class="token operator">=</span>721, y<span class="token operator">=</span>1336<span class="token punctuation">)</span>.move_to<span class="token punctuation">(</span>x<span class="token operator">=</span>238, y<span class="token operator">=</span>1336<span class="token punctuation">)</span>
 .move_to<span class="token punctuation">(</span>x<span class="token operator">=</span>717, y<span class="token operator">=</span>1809<span class="token punctuation">)</span>.release<span class="token punctuation">(</span><span class="token punctuation">)</span>.perform<span class="token punctuation">(</span><span class="token punctuation">))</span>

time.sleep<span class="token punctuation">(</span>10<span class="token punctuation">)</span>
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>

</code></pre>
<h3 id="其他操作"><a href="#其他操作" class="headerlink" title="其他操作"></a>其他操作</h3><pre class=" language-bash"><code class="language-bash"><span class="token function">import</span> <span class="token function">time</span>

from appium <span class="token function">import</span> webdriver
from appium.webdriver.connectiontype <span class="token function">import</span> ConnectionType

desired_caps <span class="token operator">=</span> dict<span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment" spellcheck="true"># 手机参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Android'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'platformVersion'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'5.1'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'deviceName'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'192.168.56.101:5555'</span>
<span class="token comment" spellcheck="true"># 应用参数</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appPackage'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'com.android.settings'</span>
desired_caps<span class="token punctuation">[</span><span class="token string">'appActivity'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'.Settings'</span>

<span class="token comment" spellcheck="true"># 获取driver</span>
driver <span class="token operator">=</span> webdriver.Remote<span class="token punctuation">(</span><span class="token string">'http://localhost:4723/wd/hub'</span>, desired_caps<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># 获取当前设备的分辨率</span>
<span class="token comment" spellcheck="true"># print(driver.get_window_size())</span>
<span class="token comment" spellcheck="true"># print(driver.get_window_size()["width"])</span>
<span class="token comment" spellcheck="true"># print(type(driver.get_window_size()["width"]))</span>

<span class="token comment" spellcheck="true"># 截图</span>
<span class="token comment" spellcheck="true"># driver.get_screenshot_as_file("screen.png")</span>
<span class="token comment" spellcheck="true"># driver.get_screenshot_as_file("/Users/Yoson/Desktop/screen.png")</span>

<span class="token comment" spellcheck="true"># # 获取当前网络</span>
<span class="token comment" spellcheck="true"># print(driver.network_connection)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 设置当前网络</span>
<span class="token comment" spellcheck="true"># driver.set_network_connection(1)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 不推荐</span>
<span class="token comment" spellcheck="true"># if driver.network_connection == 4:  # 4=data only</span>
<span class="token comment" spellcheck="true">#     print(1)</span>
<span class="token comment" spellcheck="true"># else:</span>
<span class="token comment" spellcheck="true">#     print(0)</span>
<span class="token comment" spellcheck="true">#</span>
<span class="token comment" spellcheck="true"># # 推荐的</span>
<span class="token comment" spellcheck="true"># if driver.network_connection == ConnectionType.DATA_ONLY:</span>
<span class="token comment" spellcheck="true">#     print(1)</span>
<span class="token comment" spellcheck="true"># else:</span>
<span class="token comment" spellcheck="true">#     print(0)</span>


<span class="token comment" spellcheck="true"># # 发送键到设备</span>
<span class="token comment" spellcheck="true"># # 需求：三次音量+ 返回 两次音量-</span>
<span class="token comment" spellcheck="true"># driver.press_keycode(24)</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># driver.press_keycode(24)</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># driver.press_keycode(24)</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># driver.press_keycode(4)</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># driver.press_keycode(25)</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>
<span class="token comment" spellcheck="true"># driver.press_keycode(25)</span>
<span class="token comment" spellcheck="true"># time.sleep(2)</span>

<span class="token comment" spellcheck="true"># 打开通知栏</span>
driver.open_notifications<span class="token punctuation">(</span><span class="token punctuation">)</span>

time.sleep<span class="token punctuation">(</span>3<span class="token punctuation">)</span>

<span class="token comment" spellcheck="true"># 关闭通知栏</span>
driver.press_keycode<span class="token punctuation">(</span>4<span class="token punctuation">)</span>

time.sleep<span class="token punctuation">(</span>10<span class="token punctuation">)</span>
driver.quit<span class="token punctuation">(</span><span class="token punctuation">)</span>

</code></pre>

            </div>
            <hr>

            
            <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.88rem;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff;
        background-color: #22AB38;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff;
        background-color: #019FE8;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a class="reward-link btn-floating btn-large waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close"><i class="fa fa-close"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs">
                        <li class="tab wechat-tab waves-effect waves-light"><a class="active" href="#wechat">微信</a></li>
                        <li class="tab alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                    </ul>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('#reward .reward-link').on('click', function () {
            $('#rewardModal').openModal();
        });

        $('#rewardModal .close').on('click', function () {
            $('#rewardModal').closeModal();
        });
    });
</script>
            

            <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">

<div id="article-share">
    
    <div class="social-share" data-disabled="qzone" data-wechat-qrcode-helper="<p>微信里点“发现”->“扫一扫”二维码便可查看分享。</p>"></div>
    
</div>

<script src="/libs/share/js/social-share.min.js"></script>

            <div class="reprint">
                <p>
                    <span class="reprint-tip">转载请注明: </span>
                    <a href="https://zy20081.github.io" class="b-link-green">Zhou•Yong</a>
                    <i class="fa fa-angle-right fa-lg fa-fw text-color"></i>
                    <a href="/2020/11/08/yi-dong-zi-dong-hua/" class="b-link-green">移动自动化测试</a>
                </p>
            </div>
        </div>
    </div>

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">上一篇</div>
            <div class="card">
                <a href="/2020/12/08/jmeter-jie-kou-xing-neng-ce-shi/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/19.jpg" class="responsive-img" alt="JMeter接口性能测试">
                        
                        <span class="card-title">JMeter接口性能测试</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary">JMeter JMeter是的一款接口和性能测试工具 优点：1. 开源、免费 2. 跨平台 3. 支持多协议 4. 小巧 5. 功能强大 缺点：1. 不支持IP欺骗 2. 使用JMeter无法验证JS程序，也无法验证页面UI，所以要和Sel</div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="fa fa-clock-o fa-fw icon-date"></i>2020-12-08
                        </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/测试/" class="post-category" target="_blank">
                                    测试
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/JMeter接口性能测试/" target="_blank">
                        <span class="chip bg-color">JMeter接口性能测试</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">下一篇</div>
            <div class="card">
                <a href="/2020/10/08/web-zi-dong-hua-ce-shi/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/22.jpg" class="responsive-img" alt="web自动化测试">
                        
                        <span class="card-title">web自动化测试</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary">自动化测试 web自动化测试只适用于需求变动不频繁，项目周期长，项目需要回归 Web自动化测试属于黑盒测试(功能测试)
Selenium+Python1. Python 开发环境
2. 安装selenium包
3. 安装浏览器
4. 安装浏</div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="fa fa-clock-o fa-fw icon-date"></i>2020-10-08
                            </span>
                        <span class="publish-author">
                            
                            <i class="fa fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/测试/" class="post-category" target="_blank">
                                    测试
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/web自动化测试/" target="_blank">
                        <span class="chip bg-color">web自动化测试</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>
</div>


    </div>
    <div class="col l3 hide-on-med-and-down">
        <div class="toc-widget">
            <div class="toc-title">目录</div>
            <div id="toc-content">

            </div>
        </div>
    </div>
</div>

<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });
    });
</script>
    

</main>


<footer class="page-footer bg-color">
    <div class="container row center-align">
        <div class="col s12 m8 l8 copy-right">
            本站由ZhouYong 技术分享，心得分享.
        </div>
        <div class="col s12 m4 l4 social-link"><a href="#!" class="tooltipped" data-tooltip="邮件联系我: zy20081@126.com" data-position="top" data-delay="50">
    <i class="fa fa-envelope-open"></i>
</a>
<a href="#!" class="tooltipped" data-tooltip="QQ联系我: 314153271" data-position="top" data-delay="50">
    <i class="fa fa-qq"></i>
</a>

<a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
    <i class="fa fa-rss"></i>
</a>
</div>
    </div>
</footer>

<div class="progress-bar"></div>


<!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title">搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字" class="search-input" autofocus>
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script src="/js/search.js"></script>
<script type="text/javascript">
    searchFunc("/" + "search.xml", 'searchInput', 'searchResult');
</script>
<!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fa fa-angle-up"></i>
    </a>
</div>


<script src="/libs/materialize/js/materialize.min.js"></script>
<script src="/libs/masonry/masonry.pkgd.min.js"></script>
<script src="/libs/aos/aos.js"></script>
<script src="/libs/scrollprogress/scrollProgress.min.js"></script>
<script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>

<script src="/libs/others/clicklove.js"></script>

<script src="/js/matery.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->


</body>
</html>